<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>pytils.utils</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="pytils-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

      <th class="navbar" width="100%"></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        <a href="pytils-module.html">Package&nbsp;pytils</a> ::
        Module&nbsp;utils
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
        <tr><td align="right"><span class="options">[<a href="javascript: void(0);" class="privatelink"
    onclick="toggle_private();">hide private</a>]</span></td></tr>
        <tr><td align="right"><span class="options"
            >[<a href="frames.html" target="_top">frames</a
            >]&nbsp;|&nbsp;<a href="pytils.utils-pysrc.html"
            target="_top">no&nbsp;frames</a>]</span></td></tr>
      </table>
    </td>
  </tr>
</table>
<h1 class="epydoc">Source Code for <a href="pytils.utils-module.html">Module pytils.utils</a></h1>
<pre class="py-src">
<span class="py-lineno">  1</span>  <span class="py-line"><span class="py-comment"># -*- coding: utf-8 -*-</span> </span>
<span class="py-lineno">  2</span>  <span class="py-line"><span class="py-comment"></span><span class="py-comment"># -*- test-case-name: pytils.test.test_utils -*-</span> </span>
<span class="py-lineno">  3</span>  <span class="py-line"><span class="py-comment"></span><span class="py-comment"># License: GNU GPL2</span> </span>
<span class="py-lineno">  4</span>  <span class="py-line"><span class="py-comment"></span><span class="py-comment"># Author: Pythy &lt;the.pythy@gmail.com&gt;</span> </span>
<span class="py-lineno">  5</span>  <span class="py-line"><span class="py-comment"></span><span class="py-docstring">"""</span> </span>
<span class="py-lineno">  6</span>  <span class="py-line"><span class="py-docstring">Misc utils for internal use</span> </span>
<span class="py-lineno">  7</span>  <span class="py-line"><span class="py-docstring">"""</span> </span>
<span class="py-lineno">  8</span>  <span class="py-line"> </span>
<span class="py-lineno">  9</span>  <span class="py-line"><span id="link-0" class="py-name"><a title="pytils.__id__
pytils.dt.__id__
pytils.numeral.__id__
pytils.templatetags.__id__
pytils.templatetags.pytils_dt.__id__
pytils.templatetags.pytils_numeral.__id__
pytils.templatetags.pytils_translit.__id__
pytils.test.__id__
pytils.test.test_dt.__id__
pytils.test.test_numeral.__id__
pytils.test.test_translit.__id__
pytils.test.test_utils.__id__
pytils.translit.__id__
pytils.utils.__id__" class="py-name" href="#" onclick="doclink('link-0', '__id__', 'Variable pytils.__id__=pytils-module.html#__id__,Variable pytils.dt.__id__=pytils.dt-module.html#__id__,Variable pytils.numeral.__id__=pytils.numeral-module.html#__id__,Variable pytils.templatetags.__id__=pytils.templatetags-module.html#__id__,Variable pytils.templatetags.pytils_dt.__id__=pytils.templatetags.pytils_dt-module.html#__id__,Variable pytils.templatetags.pytils_numeral.__id__=pytils.templatetags.pytils_numeral-module.html#__id__,Variable pytils.templatetags.pytils_translit.__id__=pytils.templatetags.pytils_translit-module.html#__id__,Variable pytils.test.__id__=pytils.test-module.html#__id__,Variable pytils.test.test_dt.__id__=pytils.test.test_dt-module.html#__id__,Variable pytils.test.test_numeral.__id__=pytils.test.test_numeral-module.html#__id__,Variable pytils.test.test_translit.__id__=pytils.test.test_translit-module.html#__id__,Variable pytils.test.test_utils.__id__=pytils.test.test_utils-module.html#__id__,Variable pytils.translit.__id__=pytils.translit-module.html#__id__,Variable pytils.utils.__id__=pytils.utils-module.html#__id__'); return false;">__id__</a></span></span> <span class="py-op">=</span> <span id="link-1" class="py-name"><a title="pytils.__revision__
pytils.dt.__revision__
pytils.numeral.__revision__
pytils.templatetags.__revision__
pytils.templatetags.pytils_dt.__revision__
pytils.templatetags.pytils_numeral.__revision__
pytils.templatetags.pytils_translit.__revision__
pytils.test.__revision__
pytils.test.test_dt.__revision__
pytils.test.test_numeral.__revision__
pytils.test.test_translit.__revision__
pytils.test.test_utils.__revision__
pytils.translit.__revision__
pytils.utils.__revision__" class="py-name" href="#" onclick="doclink('link-1', '__revision__', 'Variable pytils.__revision__=pytils-module.html#__revision__,Variable pytils.dt.__revision__=pytils.dt-module.html#__revision__,Variable pytils.numeral.__revision__=pytils.numeral-module.html#__revision__,Variable pytils.templatetags.__revision__=pytils.templatetags-module.html#__revision__,Variable pytils.templatetags.pytils_dt.__revision__=pytils.templatetags.pytils_dt-module.html#__revision__,Variable pytils.templatetags.pytils_numeral.__revision__=pytils.templatetags.pytils_numeral-module.html#__revision__,Variable pytils.templatetags.pytils_translit.__revision__=pytils.templatetags.pytils_translit-module.html#__revision__,Variable pytils.test.__revision__=pytils.test-module.html#__revision__,Variable pytils.test.test_dt.__revision__=pytils.test.test_dt-module.html#__revision__,Variable pytils.test.test_numeral.__revision__=pytils.test.test_numeral-module.html#__revision__,Variable pytils.test.test_translit.__revision__=pytils.test.test_translit-module.html#__revision__,Variable pytils.test.test_utils.__revision__=pytils.test.test_utils-module.html#__revision__,Variable pytils.translit.__revision__=pytils.translit-module.html#__revision__,Variable pytils.utils.__revision__=pytils.utils-module.html#__revision__'); return false;">__revision__</a></span></span> <span class="py-op">=</span> <span class="py-string">"$Id: utils.py 28 2006-10-21 08:03:02Z the.pythy $"</span> </span>
<span class="py-lineno"> 10</span>  <span class="py-line"><span id="link-2" class="py-name"><a title="pytils.__url__
pytils.dt.__url__
pytils.numeral.__url__
pytils.templatetags.__url__
pytils.templatetags.pytils_dt.__url__
pytils.templatetags.pytils_numeral.__url__
pytils.templatetags.pytils_translit.__url__
pytils.test.__url__
pytils.test.test_dt.__url__
pytils.test.test_numeral.__url__
pytils.test.test_translit.__url__
pytils.test.test_utils.__url__
pytils.translit.__url__
pytils.utils.__url__" class="py-name" href="#" onclick="doclink('link-2', '__url__', 'Variable pytils.__url__=pytils-module.html#__url__,Variable pytils.dt.__url__=pytils.dt-module.html#__url__,Variable pytils.numeral.__url__=pytils.numeral-module.html#__url__,Variable pytils.templatetags.__url__=pytils.templatetags-module.html#__url__,Variable pytils.templatetags.pytils_dt.__url__=pytils.templatetags.pytils_dt-module.html#__url__,Variable pytils.templatetags.pytils_numeral.__url__=pytils.templatetags.pytils_numeral-module.html#__url__,Variable pytils.templatetags.pytils_translit.__url__=pytils.templatetags.pytils_translit-module.html#__url__,Variable pytils.test.__url__=pytils.test-module.html#__url__,Variable pytils.test.test_dt.__url__=pytils.test.test_dt-module.html#__url__,Variable pytils.test.test_numeral.__url__=pytils.test.test_numeral-module.html#__url__,Variable pytils.test.test_translit.__url__=pytils.test.test_translit-module.html#__url__,Variable pytils.test.test_utils.__url__=pytils.test.test_utils-module.html#__url__,Variable pytils.translit.__url__=pytils.translit-module.html#__url__,Variable pytils.utils.__url__=pytils.utils-module.html#__url__'); return false;">__url__</a></span></span> <span class="py-op">=</span> <span class="py-string">"$URL: https://pythy.googlecode.com/svn/trunk/pytils/pytils/utils.py $"</span> </span>
<span class="py-lineno"> 11</span>  <span class="py-line"> </span>
<span class="py-lineno"> 12</span>  <span class="py-line"><span class="py-keyword">import</span> <span class="py-name">sys</span> </span>
<span class="py-lineno"> 13</span>  <span class="py-line"> </span>
<a name="provide_unicode"></a><div id="provide_unicode-def"><span class="py-lineno"> 14</span> <a class="py-toggle" href="#" id="provide_unicode-toggle" onclick="toggle('provide_unicode'); return false;">-</a><span class="py-line"><span class="py-keyword">def</span> <a class="py-def-name" href="pytils.utils-module.html#provide_unicode">provide_unicode</a><span class="py-op">(</span><span class="py-param">stext</span><span class="py-op">,</span> <span class="py-param">encoding</span><span class="py-op">,</span> <span class="py-param">default</span><span class="py-op">=</span><span class="py-string">u"&#1085;&#1077;&#1080;&#1079;&#1074;&#1077;&#1089;&#1090;&#1085;&#1086;"</span><span class="py-op">)</span><span class="py-op">:</span> </span>
</div><div id="provide_unicode-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="provide_unicode-expanded"><span class="py-lineno"> 15</span>  <span class="py-line">    <span class="py-docstring">"""</span> </span>
<span class="py-lineno"> 16</span>  <span class="py-line"><span class="py-docstring">    Provide Unicode from text</span> </span>
<span class="py-lineno"> 17</span>  <span class="py-line"><span class="py-docstring">    </span> </span>
<span class="py-lineno"> 18</span>  <span class="py-line"><span class="py-docstring">    @param stext: text</span> </span>
<span class="py-lineno"> 19</span>  <span class="py-line"><span class="py-docstring">    @type stext: C{str}</span> </span>
<span class="py-lineno"> 20</span>  <span class="py-line"><span class="py-docstring">    </span> </span>
<span class="py-lineno"> 21</span>  <span class="py-line"><span class="py-docstring">    @param encoding: encoding if input text</span> </span>
<span class="py-lineno"> 22</span>  <span class="py-line"><span class="py-docstring">    @type encoding: C{str}</span> </span>
<span class="py-lineno"> 23</span>  <span class="py-line"><span class="py-docstring">    </span> </span>
<span class="py-lineno"> 24</span>  <span class="py-line"><span class="py-docstring">    @return: C{unicode}</span> </span>
<span class="py-lineno"> 25</span>  <span class="py-line"><span class="py-docstring">    """</span> </span>
<span class="py-lineno"> 26</span>  <span class="py-line">    <span class="py-keyword">try</span><span class="py-op">:</span> </span>
<span class="py-lineno"> 27</span>  <span class="py-line">        <span class="py-name">utext</span> <span class="py-op">=</span> <span class="py-name">str</span><span class="py-op">(</span><span class="py-name">stext</span><span class="py-op">)</span><span class="py-op">.</span><span class="py-name">decode</span><span class="py-op">(</span><span id="link-3" class="py-name"><a title="pytils.templatetags.pytils_dt.encoding
pytils.templatetags.pytils_numeral.encoding
pytils.templatetags.pytils_translit.encoding" class="py-name" href="#" onclick="doclink('link-3', 'encoding', 'Variable pytils.templatetags.pytils_dt.encoding=pytils.templatetags.pytils_dt-module.html#encoding,Variable pytils.templatetags.pytils_numeral.encoding=pytils.templatetags.pytils_numeral-module.html#encoding,Variable pytils.templatetags.pytils_translit.encoding=pytils.templatetags.pytils_translit-module.html#encoding'); return false;">encoding</a></span></span><span class="py-op">)</span> </span>
<span class="py-lineno"> 28</span>  <span class="py-line">    <span class="py-keyword">except</span> <span class="py-name">UnicodeDecodeError</span><span class="py-op">,</span> <span class="py-name">err</span><span class="py-op">:</span> </span>
<span class="py-lineno"> 29</span>  <span class="py-line">        <span class="py-name">utext</span> <span class="py-op">=</span> <span class="py-name">default</span> <span class="py-op">%</span> <span class="py-op">{</span><span class="py-string">'error'</span><span class="py-op">:</span> <span class="py-name">err</span><span class="py-op">,</span> <span class="py-string">'value'</span><span class="py-op">:</span> <span class="py-string">u""</span><span class="py-op">}</span> </span>
<span class="py-lineno"> 30</span>  <span class="py-line">    <span class="py-keyword">return</span> <span class="py-name">utext</span> </span>
</div><span class="py-lineno"> 31</span>  <span class="py-line"> </span>
<a name="provide_str"></a><div id="provide_str-def"><span class="py-lineno"> 32</span> <a class="py-toggle" href="#" id="provide_str-toggle" onclick="toggle('provide_str'); return false;">-</a><span class="py-line"><span class="py-keyword">def</span> <a class="py-def-name" href="pytils.utils-module.html#provide_str">provide_str</a><span class="py-op">(</span><span class="py-param">utext</span><span class="py-op">,</span> <span class="py-param">encoding</span><span class="py-op">,</span> <span class="py-param">default</span><span class="py-op">=</span><span class="py-string">"unknown"</span><span class="py-op">)</span><span class="py-op">:</span> </span>
</div><div id="provide_str-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="provide_str-expanded"><span class="py-lineno"> 33</span>  <span class="py-line">    <span class="py-docstring">"""</span> </span>
<span class="py-lineno"> 34</span>  <span class="py-line"><span class="py-docstring">    Provide text from Unicode</span> </span>
<span class="py-lineno"> 35</span>  <span class="py-line"><span class="py-docstring">    </span> </span>
<span class="py-lineno"> 36</span>  <span class="py-line"><span class="py-docstring">    @param utext: unicode text</span> </span>
<span class="py-lineno"> 37</span>  <span class="py-line"><span class="py-docstring">    @type utext: C{unicode}</span> </span>
<span class="py-lineno"> 38</span>  <span class="py-line"><span class="py-docstring">    </span> </span>
<span class="py-lineno"> 39</span>  <span class="py-line"><span class="py-docstring">    @param encoding: encoding of output text</span> </span>
<span class="py-lineno"> 40</span>  <span class="py-line"><span class="py-docstring">    @type encoding: C{str}</span> </span>
<span class="py-lineno"> 41</span>  <span class="py-line"><span class="py-docstring">    </span> </span>
<span class="py-lineno"> 42</span>  <span class="py-line"><span class="py-docstring">    @return: C{str}</span> </span>
<span class="py-lineno"> 43</span>  <span class="py-line"><span class="py-docstring">    """</span> </span>
<span class="py-lineno"> 44</span>  <span class="py-line">    <span class="py-keyword">try</span><span class="py-op">:</span> </span>
<span class="py-lineno"> 45</span>  <span class="py-line">        <span class="py-name">stext</span> <span class="py-op">=</span> <span class="py-name">unicode</span><span class="py-op">(</span><span class="py-name">utext</span><span class="py-op">)</span><span class="py-op">.</span><span class="py-name">encode</span><span class="py-op">(</span><span id="link-4" class="py-name"><a title="pytils.templatetags.pytils_dt.encoding
pytils.templatetags.pytils_numeral.encoding
pytils.templatetags.pytils_translit.encoding" class="py-name" href="#" onclick="doclink('link-4', 'encoding', 'Variable pytils.templatetags.pytils_dt.encoding=pytils.templatetags.pytils_dt-module.html#encoding,Variable pytils.templatetags.pytils_numeral.encoding=pytils.templatetags.pytils_numeral-module.html#encoding,Variable pytils.templatetags.pytils_translit.encoding=pytils.templatetags.pytils_translit-module.html#encoding'); return false;">encoding</a></span></span><span class="py-op">)</span> </span>
<span class="py-lineno"> 46</span>  <span class="py-line">    <span class="py-keyword">except</span> <span class="py-name">UnicodeEncodeError</span><span class="py-op">,</span> <span class="py-name">err</span><span class="py-op">:</span> </span>
<span class="py-lineno"> 47</span>  <span class="py-line">        <span class="py-name">stext</span> <span class="py-op">=</span> <span class="py-name">default</span> <span class="py-op">%</span> <span class="py-op">{</span><span class="py-string">'error'</span><span class="py-op">:</span> <span class="py-name">err</span><span class="py-op">,</span> <span class="py-string">'value'</span><span class="py-op">:</span> <span class="py-string">""</span><span class="py-op">}</span> </span>
<span class="py-lineno"> 48</span>  <span class="py-line">    <span class="py-keyword">return</span> <span class="py-name">stext</span> </span>
</div><span class="py-lineno"> 49</span>  <span class="py-line"> </span>
<a name="get_value_by_name"></a><div id="get_value_by_name-def"><span class="py-lineno"> 50</span> <a class="py-toggle" href="#" id="get_value_by_name-toggle" onclick="toggle('get_value_by_name'); return false;">-</a><span class="py-line"><span class="py-keyword">def</span> <a class="py-def-name" href="pytils.utils-module.html#get_value_by_name">get_value_by_name</a><span class="py-op">(</span><span class="py-param">variable_name</span><span class="py-op">,</span> <span class="py-param">depth</span><span class="py-op">=</span><span class="py-number">1</span><span class="py-op">)</span><span class="py-op">:</span> </span>
</div><div id="get_value_by_name-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="get_value_by_name-expanded"><span class="py-lineno"> 51</span>  <span class="py-line">    <span class="py-docstring">"""</span> </span>
<span class="py-lineno"> 52</span>  <span class="py-line"><span class="py-docstring">    Return value of variable by it's name</span> </span>
<span class="py-lineno"> 53</span>  <span class="py-line"><span class="py-docstring"></span> </span>
<span class="py-lineno"> 54</span>  <span class="py-line"><span class="py-docstring">    @param variable_name: name of variable</span> </span>
<span class="py-lineno"> 55</span>  <span class="py-line"><span class="py-docstring">    @type variable_name: C{str}</span> </span>
<span class="py-lineno"> 56</span>  <span class="py-line"><span class="py-docstring"></span> </span>
<span class="py-lineno"> 57</span>  <span class="py-line"><span class="py-docstring">    @param depth: stack depth</span> </span>
<span class="py-lineno"> 58</span>  <span class="py-line"><span class="py-docstring">    @type depth: C{int}</span> </span>
<span class="py-lineno"> 59</span>  <span class="py-line"><span class="py-docstring"></span> </span>
<span class="py-lineno"> 60</span>  <span class="py-line"><span class="py-docstring">    @raise RuntimeError: when unable to fetch variable</span> </span>
<span class="py-lineno"> 61</span>  <span class="py-line"><span class="py-docstring">    """</span> </span>
<span class="py-lineno"> 62</span>  <span class="py-line">    <span class="py-keyword">try</span><span class="py-op">:</span> </span>
<span class="py-lineno"> 63</span>  <span class="py-line">        <span class="py-name">variable_value</span> <span class="py-op">=</span> <span class="py-name">sys</span><span class="py-op">.</span><span class="py-name">_getframe</span><span class="py-op">(</span><span class="py-name">depth</span><span class="py-op">)</span><span class="py-op">.</span><span class="py-name">f_locals</span><span class="py-op">[</span><span class="py-name">variable_name</span><span class="py-op">]</span> </span>
<span class="py-lineno"> 64</span>  <span class="py-line">    <span class="py-keyword">except</span> <span class="py-name">KeyError</span><span class="py-op">:</span> </span>
<span class="py-lineno"> 65</span>  <span class="py-line">        <span class="py-keyword">raise</span> <span class="py-name">RuntimeError</span><span class="py-op">(</span><span class="py-string">"Unable to fetch variable %s (depth %d)"</span> <span class="py-op">%</span> \ </span>
<span class="py-lineno"> 66</span>  <span class="py-line">                           <span class="py-op">(</span><span class="py-name">variable_name</span><span class="py-op">,</span> <span class="py-name">depth</span><span class="py-op">)</span><span class="py-op">)</span> </span>
<span class="py-lineno"> 67</span>  <span class="py-line">    <span class="py-keyword">return</span> <span class="py-name">variable_value</span> </span>
</div><span class="py-lineno"> 68</span>  <span class="py-line">     </span>
<span class="py-lineno"> 69</span>  <span class="py-line"> </span>
<a name="check_type"></a><div id="check_type-def"><span class="py-lineno"> 70</span> <a class="py-toggle" href="#" id="check_type-toggle" onclick="toggle('check_type'); return false;">-</a><span class="py-line"><span class="py-keyword">def</span> <a class="py-def-name" href="pytils.utils-module.html#check_type">check_type</a><span class="py-op">(</span><span class="py-param">variable_name</span><span class="py-op">,</span> <span class="py-param">typ</span><span class="py-op">)</span><span class="py-op">:</span> </span>
</div><div id="check_type-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="check_type-expanded"><span class="py-lineno"> 71</span>  <span class="py-line">    <span class="py-docstring">"""</span> </span>
<span class="py-lineno"> 72</span>  <span class="py-line"><span class="py-docstring">    Checks type of variable</span> </span>
<span class="py-lineno"> 73</span>  <span class="py-line"><span class="py-docstring"></span> </span>
<span class="py-lineno"> 74</span>  <span class="py-line"><span class="py-docstring">    @param variable_name: name of variable</span> </span>
<span class="py-lineno"> 75</span>  <span class="py-line"><span class="py-docstring">    @type variable_name: C{str}</span> </span>
<span class="py-lineno"> 76</span>  <span class="py-line"><span class="py-docstring"></span> </span>
<span class="py-lineno"> 77</span>  <span class="py-line"><span class="py-docstring">    @param typ: type checking for</span> </span>
<span class="py-lineno"> 78</span>  <span class="py-line"><span class="py-docstring">    @type typ: C{type} or C{tuple} of types</span> </span>
<span class="py-lineno"> 79</span>  <span class="py-line"><span class="py-docstring"></span> </span>
<span class="py-lineno"> 80</span>  <span class="py-line"><span class="py-docstring">    @return: None when check successful</span> </span>
<span class="py-lineno"> 81</span>  <span class="py-line"><span class="py-docstring"></span> </span>
<span class="py-lineno"> 82</span>  <span class="py-line"><span class="py-docstring">    @raise TypeError: check failed</span> </span>
<span class="py-lineno"> 83</span>  <span class="py-line"><span class="py-docstring">    """</span> </span>
<span class="py-lineno"> 84</span>  <span class="py-line">    <span class="py-name">variable_value</span> <span class="py-op">=</span> <span id="link-5" class="py-name"><a title="pytils.utils.get_value_by_name" class="py-name" href="#" onclick="doclink('link-5', 'get_value_by_name', 'Function pytils.utils.get_value_by_name()=pytils.utils-module.html#get_value_by_name'); return false;">get_value_by_name</a></span></span><span class="py-op">(</span><span class="py-name">variable_name</span><span class="py-op">,</span> <span class="py-number">2</span><span class="py-op">)</span> </span>
<span class="py-lineno"> 85</span>  <span class="py-line">    <span class="py-keyword">if</span> <span class="py-keyword">not</span> <span class="py-name">isinstance</span><span class="py-op">(</span><span class="py-name">variable_value</span><span class="py-op">,</span> <span class="py-name">typ</span><span class="py-op">)</span><span class="py-op">:</span> </span>
<span class="py-lineno"> 86</span>  <span class="py-line">        <span class="py-keyword">raise</span> <span class="py-name">TypeError</span><span class="py-op">(</span><span class="py-string">"%s must be %s, not %s"</span> <span class="py-op">%</span> \ </span>
<span class="py-lineno"> 87</span>  <span class="py-line">                        <span class="py-op">(</span><span class="py-name">variable_name</span><span class="py-op">,</span> <span class="py-name">str</span><span class="py-op">(</span><span class="py-name">typ</span><span class="py-op">)</span><span class="py-op">,</span> <span class="py-name">type</span><span class="py-op">(</span><span class="py-name">variable_value</span><span class="py-op">)</span><span class="py-op">)</span><span class="py-op">)</span> </span>
</div><span class="py-lineno"> 88</span>  <span class="py-line"> </span>
<a name="check_length"></a><div id="check_length-def"><span class="py-lineno"> 89</span> <a class="py-toggle" href="#" id="check_length-toggle" onclick="toggle('check_length'); return false;">-</a><span class="py-line"><span class="py-keyword">def</span> <a class="py-def-name" href="pytils.utils-module.html#check_length">check_length</a><span class="py-op">(</span><span class="py-param">variable_name</span><span class="py-op">,</span> <span class="py-param">length</span><span class="py-op">)</span><span class="py-op">:</span> </span>
</div><div id="check_length-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="check_length-expanded"><span class="py-lineno"> 90</span>  <span class="py-line">    <span class="py-docstring">"""</span> </span>
<span class="py-lineno"> 91</span>  <span class="py-line"><span class="py-docstring">    Checks length of variable's value</span> </span>
<span class="py-lineno"> 92</span>  <span class="py-line"><span class="py-docstring"></span> </span>
<span class="py-lineno"> 93</span>  <span class="py-line"><span class="py-docstring">    @param variable_name: name of variable</span> </span>
<span class="py-lineno"> 94</span>  <span class="py-line"><span class="py-docstring">    @type variable_name: C{str}</span> </span>
<span class="py-lineno"> 95</span>  <span class="py-line"><span class="py-docstring"></span> </span>
<span class="py-lineno"> 96</span>  <span class="py-line"><span class="py-docstring">    @param length: length checking for</span> </span>
<span class="py-lineno"> 97</span>  <span class="py-line"><span class="py-docstring">    @type length: C{int}</span> </span>
<span class="py-lineno"> 98</span>  <span class="py-line"><span class="py-docstring"></span> </span>
<span class="py-lineno"> 99</span>  <span class="py-line"><span class="py-docstring">    @return: None when check successful</span> </span>
<span class="py-lineno">100</span>  <span class="py-line"><span class="py-docstring"></span> </span>
<span class="py-lineno">101</span>  <span class="py-line"><span class="py-docstring">    @raise ValueError: check failed</span> </span>
<span class="py-lineno">102</span>  <span class="py-line"><span class="py-docstring">    """</span> </span>
<span class="py-lineno">103</span>  <span class="py-line">    <span class="py-name">variable_value</span> <span class="py-op">=</span> <span id="link-6" class="py-name"><a title="pytils.utils.get_value_by_name" class="py-name" href="#" onclick="doclink('link-6', 'get_value_by_name', 'Function pytils.utils.get_value_by_name()=pytils.utils-module.html#get_value_by_name'); return false;">get_value_by_name</a></span></span><span class="py-op">(</span><span class="py-name">variable_name</span><span class="py-op">,</span> <span class="py-number">2</span><span class="py-op">)</span> </span>
<span class="py-lineno">104</span>  <span class="py-line">    <span class="py-name">_length</span> <span class="py-op">=</span> <span class="py-name">len</span><span class="py-op">(</span><span class="py-name">variable_value</span><span class="py-op">)</span> </span>
<span class="py-lineno">105</span>  <span class="py-line">    <span class="py-keyword">if</span> <span class="py-name">_length</span> <span class="py-op">!=</span> <span class="py-name">length</span><span class="py-op">:</span> </span>
<span class="py-lineno">106</span>  <span class="py-line">        <span class="py-keyword">raise</span> <span class="py-name">ValueError</span><span class="py-op">(</span><span class="py-string">"%s's length must be %d, but it %d"</span> <span class="py-op">%</span> \ </span>
<span class="py-lineno">107</span>  <span class="py-line">                         <span class="py-op">(</span><span class="py-name">variable_name</span><span class="py-op">,</span> <span class="py-name">length</span><span class="py-op">,</span> <span class="py-name">_length</span><span class="py-op">)</span><span class="py-op">)</span> </span>
</div><span class="py-lineno">108</span>  <span class="py-line"> </span>
<a name="check_positive"></a><div id="check_positive-def"><span class="py-lineno">109</span> <a class="py-toggle" href="#" id="check_positive-toggle" onclick="toggle('check_positive'); return false;">-</a><span class="py-line"><span class="py-keyword">def</span> <a class="py-def-name" href="pytils.utils-module.html#check_positive">check_positive</a><span class="py-op">(</span><span class="py-param">variable_name</span><span class="py-op">,</span> <span class="py-param">strict</span><span class="py-op">=</span><span class="py-name">False</span><span class="py-op">)</span><span class="py-op">:</span> </span>
</div><div id="check_positive-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="check_positive-expanded"><span class="py-lineno">110</span>  <span class="py-line">    <span class="py-docstring">"""</span> </span>
<span class="py-lineno">111</span>  <span class="py-line"><span class="py-docstring">    Checks if variable is positive</span> </span>
<span class="py-lineno">112</span>  <span class="py-line"><span class="py-docstring"></span> </span>
<span class="py-lineno">113</span>  <span class="py-line"><span class="py-docstring">    @param variable_name: name of variable</span> </span>
<span class="py-lineno">114</span>  <span class="py-line"><span class="py-docstring">    @type variable_name: C{str}</span> </span>
<span class="py-lineno">115</span>  <span class="py-line"><span class="py-docstring"></span> </span>
<span class="py-lineno">116</span>  <span class="py-line"><span class="py-docstring">    @return: None when check successful</span> </span>
<span class="py-lineno">117</span>  <span class="py-line"><span class="py-docstring"></span> </span>
<span class="py-lineno">118</span>  <span class="py-line"><span class="py-docstring">    @raise ValueError: check failed</span> </span>
<span class="py-lineno">119</span>  <span class="py-line"><span class="py-docstring">    """</span> </span>
<span class="py-lineno">120</span>  <span class="py-line">    <span class="py-name">variable_value</span> <span class="py-op">=</span> <span id="link-7" class="py-name"><a title="pytils.utils.get_value_by_name" class="py-name" href="#" onclick="doclink('link-7', 'get_value_by_name', 'Function pytils.utils.get_value_by_name()=pytils.utils-module.html#get_value_by_name'); return false;">get_value_by_name</a></span></span><span class="py-op">(</span><span class="py-name">variable_name</span><span class="py-op">,</span> <span class="py-number">2</span><span class="py-op">)</span> </span>
<span class="py-lineno">121</span>  <span class="py-line">    <span class="py-keyword">if</span> <span class="py-keyword">not</span> <span class="py-name">strict</span> <span class="py-keyword">and</span> <span class="py-name">variable_value</span> <span class="py-op">&lt;</span> <span class="py-number">0</span><span class="py-op">:</span> </span>
<span class="py-lineno">122</span>  <span class="py-line">        <span class="py-keyword">raise</span> <span class="py-name">ValueError</span><span class="py-op">(</span><span class="py-string">"%s must be positive or zero, not %s"</span> <span class="py-op">%</span> \ </span>
<span class="py-lineno">123</span>  <span class="py-line">                         <span class="py-op">(</span><span class="py-name">variable_name</span><span class="py-op">,</span> <span class="py-name">str</span><span class="py-op">(</span><span class="py-name">variable_value</span><span class="py-op">)</span><span class="py-op">)</span><span class="py-op">)</span> </span>
<span class="py-lineno">124</span>  <span class="py-line">    <span class="py-keyword">if</span> <span class="py-name">strict</span> <span class="py-keyword">and</span> <span class="py-name">variable_value</span> <span class="py-op">&lt;=</span> <span class="py-number">0</span><span class="py-op">:</span> </span>
<span class="py-lineno">125</span>  <span class="py-line">        <span class="py-keyword">raise</span> <span class="py-name">ValueError</span><span class="py-op">(</span><span class="py-string">"%s must be positive, not %s"</span> <span class="py-op">%</span> \ </span>
<span class="py-lineno">126</span>  <span class="py-line">                         <span class="py-op">(</span><span class="py-name">variable_name</span><span class="py-op">,</span> <span class="py-name">str</span><span class="py-op">(</span><span class="py-name">variable_value</span><span class="py-op">)</span><span class="py-op">)</span><span class="py-op">)</span> </span>
</div><span class="py-lineno">127</span>  <span class="py-line"> </span><script type="text/javascript">
<!--
expandto(location.href);
// -->
</script>
</pre>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="pytils-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

      <th class="navbar" width="100%"></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">Generated by Epydoc
        3.0alpha3 on Sun Oct 29 00:35:03 2006</td>
    <td align="right" class="footer">
      <a href="http://epydoc.sourceforge.net">http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie()
  // -->
</script>
  
</body>
</html>
